module \test::Test

import lang::java::m3::Core;
import lang::java::jdt::m3::Core;
import lang::ofg::ast::Java2OFG;
import lang::ofg::ast::FlowLanguage;
import IO;
import ar::FlowGraphsAndClassDiagrams;
import DateTime;

public void Start()
{
	println("###### BEGIN ####################");
	start_time = now();
	
	// ##### Make sure to set myModel and p to the correct Eclipse project! #####
	
	myModel = createM3FromEclipseProject(|project://eLib|);
	p = createOFG(|project://eLib|);
	
	//myModel = createM3FromEclipseProject(|project://Test|);
	//p = createOFG(|project://Test|);
	
	myModel = createM3FromEclipseProject(|project://nekohtml-0.9.5/src/html/org/cyberneko/html|);
	p = createOFG(|project://nekohtml-0.9.5/src/html/org/cyberneko/html|);
	
	//myModel = createM3FromEclipseProject(|project://nekohtml-1.9.14/src/html/org/cyberneko/html|);
	//p = createOFG(|project://nekohtml-1.9.14/src/html/org/cyberneko/html|);
	
	// ##### Make sure to set myModel and p to the correct Eclipse project! #####
	
	// Set this boolean to true in order to print extra OFG debug output (GEN, OUT sets, etc)
	bool OFG_debug_output = false;
	
	println("###### OFG ALGO START ####################");
	OFG = buildGraph(p);
	GENFORWARD = buildGenSet(p, true);
	GENBACKWARD = buildGenSet(p, false);
	KILL = { };
	OUTFORWARD = prop(OFG, GENFORWARD, KILL, true);
	OUTBACKWARD = prop(OFG, GENBACKWARD, KILL, false);
	OUTFINAL = OUTFORWARD + OUTBACKWARD;
	println("###### OFG ALGO DONE ####################");
	println("###### GENERATING DIAGRAM ####################");
	// This step might a while depending on your PC speed; for eLib it takes 30 seconds on my 2.7 Ghz dual-core laptop.
	drawDiagramOfGraph(OUTFINAL, p, myModel);
	println("###### END ####################");
	
	if (OFG_debug_output == true)
	{
		println("###### EXTRA OFG DEBUG OUTPUT: ####################");
		println("###### FORWARD GENERATION ####################");
		for (g <- GENFORWARD)
		{
			println(g);
		}
		println("###### BACKWARD GENERATION ####################");
		for (g <- GENBACKWARD)
		{
			println(g);
		}
		println("###### OUTFORWARD ####################");
		for (g <- OUTFORWARD)
		{
			println(g);
		}
		println("###### OUTBACKWARD ####################");
		for (g <- OUTBACKWARD)
		{
			println(g);
		}
		println("###### OUTFINAL ####################");
		for (g <- OUTFINAL)
		{
			println(g);
		}
		println("###### END OF EXTRA DEBUG OUTPUT ####################");
	}
	
	end_time = now();
	total_duration = (end_time - start_time);
	println("Duration: <total_duration.hours> hours : <total_duration.minutes> minutes : <total_duration.seconds> seconds");
}